package com.lxg.service.adminService.impl;

import com.lxg.dao.AdminDao;
import com.lxg.pojo.Admin;
import com.lxg.service.adminService.AdminAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class AdminAdminServiceImpl implements AdminAdminService {
    @Autowired
    AdminDao adminDao;


    /**
     * 获取全部管理员的信息
     *
     * @return allAdmin
     */
    @Override
    public ArrayList<Admin> getAllAdmin() {
        ArrayList<Admin> allAdmin = adminDao.getAllAdmin();
        return allAdmin;
    }


    /**
     * 根据传入的 aid，查找对应管理员
     *
     * @param aid
     * @return admin
     */
    @Override
    public Admin getAdminByAid(Integer aid) {
        Admin admin = adminDao.getAdminByAid(aid);
        return admin;
    }


    /**
     * 管理员根据aid删除普通管理员
     *
     * @param aid
     */
    @Override
    public boolean deleteAdminByAid(Integer aid) {
        adminDao.deleteAdminByAid(aid);
        return true;
    }


    /**
     * 超级管理员添加一个普通管理员
     * status为0时添加一个普通管理员，为1时为超级管理员
     */
    @Override
    public boolean addAdmin(String username, String password) {


        Admin admin = adminDao.checkUsername(username);
        if(admin==null){
            adminDao.addAdmin(username, password);
        }else {

        }
        return true;
    }

    @Override
    public Integer getSuperAdminNum() {
        Integer superAdminNum = adminDao.getSuperAdminNum();
        return superAdminNum;
    }

    @Override
    public Integer getAmdinNum() {
        Integer adminNum = adminDao.getAdminNum();
        return adminNum;
    }

    @Override
    public ArrayList<Admin> getAllLikeAdminByUserName(String username) {
        ArrayList<Admin> allLikeAdminByUsername = adminDao.getAllLikeAdminByUsername(username);
        return allLikeAdminByUsername;
    }

    @Override
    public boolean updateAdmin(String username, String password, Integer aid) {
        adminDao.updateAdmin(username, password, aid);
        return true;
    }
}
